package com.zyx.springbootkafka.controller;

import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/kafka")
public class ProducerController {

    @Resource
    KafkaTemplate<String, String> kafkaTemplate;

    @RequestMapping("/zyx")
    public String data(@RequestBody String msg){
        // 通过kafka发送出去
        kafkaTemplate.send("first", msg);
        System.out.println(msg);
        return "ok";
    }
}
